﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using KeRui.Common;


public partial class Manage_System_LicenceItem : System.Web.UI.Page
{
    protected KeRui.BLL.SysLicense bllSysLicense;
    protected KeRui.Model.SysLicense modelSysLicense = new KeRui.Model.SysLicense();
    public string Act = ManageHelper.PageAct();
    private ManageErrMsg nsb = new ManageErrMsg();
    protected string ActFlag = "addsave";
    protected string ActName = "添加";
    protected void Page_Load(object sender, EventArgs e)
    {
        ManageHelper.CheckAdminLogin();//判断登录状态
        ManageHelper.CheckAdminPower("system_configlicense");//权限
        bllSysLicense = new KeRui.BLL.SysLicense();
        switch (Act)
        {
            case "addsave":
                SysLicenseAdd();
                break;
            case "edit":
                Edit();
                break;
            case "editsave":
                EditSave();
                break;
            case "del":
                Del();
                break;
            default:
                break;
        }//<!--<%=bllSysLicense.GetMaxOrderID() %>-->
    }


    #region 添加
    private void SysLicenseAdd()
    {
        //bllSysLicense = new KeRui.BLL.SysLicense();
        ManageHelper.CheckAdminPower("system_configlicenseadd");//权限
        modelSysLicense.Domain = Utils.ChkSQL(PageRequest.GetString("Domain"));
        if (modelSysLicense.Domain == "")
        {
            nsb.AddErr("请输入域名。");
        }
        modelSysLicense.ServerIP = Utils.ChkSQL(PageRequest.GetString("ServerIP"));
        if (modelSysLicense.ServerIP == "")
        {
            nsb.AddErr("请输入服务器IP。");
        }
        modelSysLicense.LicenseCode = Utils.ChkSQL(PageRequest.GetString("LicenseCode"));
        if (modelSysLicense.LicenseCode == "")
        {
            nsb.AddErr("请输入许可证。");
        }
        int RetFlag = bllSysLicense.Add(modelSysLicense);
        if (RetFlag == 1)
        {
            nsb.AddErr("对不起！该服务器IP已被使用。");
            nsb.ChkErr();
        }
        else
        {
            ManageHelper.AddLog("system_configlicenseadd", "添加了“" + modelSysLicense.Domain + "”许可证。");//写日志
            Response.Redirect("LicenseList.aspx?sucmsg=添加成功。");
        }
    }
    #endregion

    #region 反显修改页面
    private void Edit()
    {
        ActFlag = "editsave";
        ActName = "修改";
        int LicenseID = PageRequest.GetInt("ID", -1);
        if (LicenseID == -1)
        {
            nsb.AddErr("该站点不存在。");
            nsb.ChkErr();
        }
        modelSysLicense = bllSysLicense.GetModel(LicenseID);
        if(modelSysLicense.IsActivated==1)
        {
            nsb.AddErr("产品已激活，无法修改。");
            nsb.ChkErr();
        }
    }
    #endregion

    #region 修改时保存
    private void EditSave()
    {
        ManageHelper.CheckAdminPower("system_configlicenseedit");//权限
        modelSysLicense.LicenseID = PageRequest.GetInt("LicenseID", -1);
        modelSysLicense.Domain = Utils.ChkSQL(PageRequest.GetString("Domain"));
        if (modelSysLicense.Domain == "")
        {
            nsb.AddErr("请输入域名。");
        }
        modelSysLicense.ServerIP = Utils.ChkSQL(PageRequest.GetString("ServerIP"));
        if (modelSysLicense.ServerIP == "")
        {
            nsb.AddErr("请输入服务器IP。");
        }
        modelSysLicense.LicenseCode = Utils.ChkSQL(PageRequest.GetString("LicenseCode"));
        if (modelSysLicense.LicenseCode == "")
        {
            nsb.AddErr("请输入许可证。");
        }
        int RetFlag = bllSysLicense.Update(modelSysLicense);
        if (RetFlag == 1)
        {
            nsb.AddErr("对不起！该域名和服务器IP已被使用。");
            nsb.ChkErr();
        }
        else
        {
            ManageHelper.AddLog("system_configlicenseedit", "修改了“" + modelSysLicense.Domain + "”许可证。");//写日志
            Response.Redirect("LicenseList.aspx?act=edit&id=" + modelSysLicense.LicenseID + "&sucmsg=修改成功。");
        }
    }
    #endregion

    #region 删除
    private void Del()
    {

        ManageHelper.CheckAdminPower("system_configlicensedel");//权限
        int LicenseID = PageRequest.GetInt("ID", -1);
        if (LicenseID == -1)
        {
            nsb.AddErr("该站点不存在。");
            nsb.ChkErr();
        }

        modelSysLicense = bllSysLicense.GetModel(LicenseID);
        if (modelSysLicense.IsActivated == 1)
        {
            nsb.AddErr("产品已激活，无法删除。");
            nsb.ChkErr();
        }

        if (bllSysLicense.Delete(LicenseID) == 1)
        {

        }
        else
        {
            ManageHelper.AddLog("system_configlicensedel", "删除了“" + modelSysLicense.Domain + "”许可证。");//写日志
            Response.Redirect("LicenseList.aspx?sucmsg=恭喜。删除成功。");
        }
    }
    #endregion
}
